package com.algorithm.ch1.cjm.iteration;

import java.util.Scanner;

/**
 * 输出杨辉三角形
 * 限定用一个数组完成
 *
 * @Author: Jie Ming Chen
 * @Date: 2018/10/5
 * @Version 1.0
 */
public class YangHuiSanJiao {

    public static void main(String[] args) {

        System.out.println("请输入需要打印的阶数：");

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int[] a = new int[n];
        System.out.println("1");
        System.out.println("1" + " " + "1");

        a[0] = 1;
        a[1] = 1;
        for (int i = 2; i < n; i++) {

            a[0] = a[i] = 1;

            for (int j = i -1; j > 0; j--) {
                a[j] = a[j - 1] + a[j];
            }

            for (int j = 0; j < i + 1; j++) {
                System.out.print(a[j] + " ");
            }
            System.out.println();
        }
    }

}
